/*
* @Author: obsidian
* @Date:   2016-03-01 10:22:51
* @Last Modified by:   obsidian
* @Last Modified time: 2016-04-22 09:10:20
*/
#include "../lcd_global.h"
#include "../lcd.h"
#include "menu_pid.h"
#include "module/steer/steer.h"
#include "module/stopsteer/stopsteer.h"
#include "module/GPS/GPS.h"
#include "control/GPSpath/GPSpath.h"
#include "module/pid/pid.h"
#include "control/store/store.h"
#include "module/brake/brake.h"
#include "module/gpsteer/gpsteer.h"
#include "code/driver/delay/inc/delay.h"
#include "control/car.h"
#include "module/gps/gps.h"
#include "math.h"
#include "module/ledboard/ledboard.h"


void menu_set_pid0_10_input(void *parg);

void menu_set_pid11_12_input(void *parg);

void menu_set_pid13_14_input(void *parg);

void menu_set_pid15_17_input(void *parg);

void menu_set_pid18_25_input(void *parg);

void menu_pid_init(void *parg);
struct Item pid_i[MAX_ITEM_NUM] = 
{
	{.ctx = "1.car1_startY", .id = 1, .ctx_len = 11, .flag = FILE,   .value_type = FLOAT, .p_value = &car_para[0].l_start_y, .func_enter = nop, .func_exec = input, .func_input_callback = nop, .func_back = nop},
	{.ctx = "2.car2_startY", .id = 2, .ctx_len = 11, .flag = FILE,   .value_type = FLOAT, .p_value =&car_para[1].l_start_y, .func_enter = nop, .func_exec = input, .func_input_callback = nop, .func_back = nop},
	{.ctx = "3.lrvt", .id = 3, .ctx_len = 4, .flag = FILE,   .value_type = FLOAT, .p_value = &gpspath.leftrivrot, .func_enter = nop, .func_exec = input, .func_input_callback = nop, .func_back = nop},
	{.ctx = "4.rrvt", .id = 4, .ctx_len = 4, .flag = FILE,   .value_type = FLOAT, .p_value = &gpspath.rightrivrot, .func_enter = nop, .func_exec = input, .func_input_callback = nop, .func_back = nop},
	{.ctx = "5.bsradian", .id = 5, .ctx_len = 8, .flag = FILE,   .value_type = FLOAT, .p_value = &gps.base_radian, .func_enter = nop, .func_exec = input, .func_input_callback = nop, .func_back = nop},

};

struct Node pid_n = 
{
    // .itemnum            =       sizeof(pid_i) / sizeof(pid_i[0]),
    // .page_num           =       sizeof(pid_i) / sizeof(pid_i[0]) / PAGE_SIZE,
    .page_index         =       0,  //page_index
    .node_id            =       2,  //node_id
    .p_item             =       pid_i,
    .position           =       {0, 0},
    .parent             =       &control_n,
    .child              =       {0},
    .init               =       menu_pid_init,
};

void menu_pid_init(void *parg)
{
    unsigned char i = 0;
    for(i = 0;i < MAX_ITEM_NUM;i ++)
    {
        if(pid_i[i].ctx[0] == 0){break;}
        pid_n.itemnum ++;
    }
    pid_n.page_num = pid_n.itemnum / PAGE_SIZE;

//     unsigned char i = 0;
    //for(i = 0;i < pid_n.itemnum; i ++)
    //{
        pid_i[0].p_value = (void *)&pid.pid_list[0].kp;
        pid_i[1].p_value = (void *)&pid.pid_list[10].kp;
        pid_i[2].p_value = (void *)&pid.pid_list[11].kp;
    //} 
     pid_n.save = pid.save;
}

void menu_set_pid0_10_input(void *parg)
{
    unsigned char i = 0;
    for(i = 1;i <= 9;i ++)
    {
        pid.pid_list[i] = pid.pid_list[0];
    }
}

void menu_set_pid11_12_input(void *parg)
{
    // unsigned char i = 0;
    // for(i = 12;i <= 12;i ++)
    // {
    //     pid.pid_list[i] = pid.pid_list[11];
    // }
}


void menu_set_pid15_17_input(void *parg)
{
    unsigned char i = 0;
    for(i = 16;i <= 17;i ++)
    {
        pid.pid_list[i] = pid.pid_list[15];
    }
}

void menu_set_pid18_25_input(void *parg)
{
    unsigned char i = 0;
    for(i = 19;i < 25;i ++)
    {
        pid.pid_list[i] = pid.pid_list[18];
    }
}

void menu_set_pid13_14_input(void *parg)
{
    unsigned char i = 0;
    for(i = 12;i <= 24;i ++)
    {
        pid.pid_list[i] = pid.pid_list[11];
    }
}
